#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int size;
    printf("Enter size of magic square: ");
    scanf("%d", &size);

    int i = 1, j = 0, k = (size - 1) / 2,
        square[size][size];
    
    bool test[size][size];

    for (int m = 0; m < size; m++)
    {
        for (int n = 0; n < size; n++)
            test[m][n] = false;
    }
    
    while (i <= size * size)
    {
        if (!test[j][k])
        {
            square[j][k] = i;
            test[j][k] = true;
            j = (j + size - 1) % size;
            k = (k + 1) % size;
        } else {
            j = (j + 2) % size;
            k = (k + size - 1) % size;
            square[j][k] = i;
            test[j][k] = true;
            j = (j + size - 1) % size;
            k = (k + 1) % size;
        } 
        i++;
    }

    for (int m = 0; m < size; m++)
    {
        printf("\n");
        for (int n = 0; n < size; n++)
            printf("%d\t", square[m][n]);
    }
    
    return 0;
}